using FairyGUI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Resources;
using DG.Tweening;
using UnityEngine;

namespace Bingo.FairyGUI
{
    public static class FairyGUIExtension
    {
        #region ==============UI显示效果统一修改

        /// <summary>
        /// 投影效果,语言表等初始化text初始化
        /// 注：FairyGUi中勾选了投影，这里的就不会触发，执行顺序问题
        /// </summary>
        public static void TextEffectInit(GTextField textField)
        {
            textField.shadowOffset = new Vector2(0, 6);
//            if (textField.data != null)
//            {
//                string lan = Facades.Localization.GetText(textField.data.ToString());
//                if (lan.Length > 0)
//                    textField.text = lan;
//            }
        }

        #endregion


        #region ==============事件监听，方法扩展，方便统一修改

        private static GObject _BeforeData = null; //变化之前的数据

        public static void G_TouchBegin(GObject gobj)
        {
            //保存变化前数据
            _BeforeData = new GObject();
            _BeforeData.scale = gobj.scale;
            _BeforeData.alpha = gobj.alpha;
            _BeforeData.pivot = gobj.pivot;

            gobj.SetPivot(0.5f, 0.5f);
            GTweener gTweener = gobj.TweenScale(gobj.scale * 1.1f, 0.2f).SetEase(EaseType.QuadOut);
            gobj.TweenFade(0.8f, 0.2f).SetEase(EaseType.QuadOut);
        }

        public static void G_TouchEnd(GObject gobj)
        {
            //这里播放动画会产生的问题
            //ui的显示对象和数据对象都销毁， 动画还没有播放完毕
            gobj.scale = _BeforeData.scale;
            gobj.alpha = _BeforeData.alpha;
            gobj.pivot = _BeforeData.pivot;
            GTween.Kill(gobj);
        }

        public static void G_Click(GObject gobj)
        {
            AudioController.Instance.PlayAudio(EAudioType.EBtnClick);
        }

        #endregion


        #region  备份

        // private const string Name_OnClick = "onClick";
        /// <summary>
        /// 所有事件分发中心有调用过
        /// </summary>
        /// <param name="eventContext"></param>
//        public static void OnFGUIInput(EventContext eventContext)
//        {
////            if (eventContext.type == "onClick")
////            {
////                OnFGUIClick(eventContext);
////            }
//        }

        #endregion
    }
}